package com.xieyong.leetcode;

import java.util.ArrayList;
import java.util.List;

public class Leetcode386 {
    public static void main(String[] args) {
        Leetcode386 leetcode386 = new Leetcode386();
        List<Integer> integers = leetcode386.lexicalOrder(213);
        System.out.println(integers);
    }


    public List<Integer> lexicalOrder(int n) {
        List<Integer> reslist = new ArrayList<>();
        for (int i = 1; i < 10; i++) {
            if (i <= n) {
                reslist.add(i);
                getres(n,i,reslist);
            }
        }
        return reslist;
    }

    public void getres (int n, int parent,List<Integer> list)  {
        for (int i = 0; i < 10; i++) {
            int temp = parent*10+i;
            if (temp <= n && temp != 0) {
                list.add(temp);
                getres(n,temp,list);
            }
        }
    }
}
